<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>审批</title>
    <script src="../layui/layui.js"></script>
    <link rel="stylesheet" href="../layui/css/layui.css">
    <script src="../src/static/jquery.js"></script>
    <link rel="stylesheet" href="examine.css">
</head>
<body>
<div>
    <div class="tupian">
        <img src="../src/images/logo_yellow.png" height="74" width="294"/>
    </div>
    <div class="nav">检索条件<label class="nav_l"></label></div>
    <form class="layui-form" action="">
        <!--<div class="layui-form-item" style="display: inline-block">-->
        <!--<label class="layui-form-label">公司名称</label>-->
        <!--<div class="layui-input-inline">-->
        <!--<input type="text" name="title" required lay-verify="required" placeholder="请输入"-->
        <!--autocomplete="off" class="layui-input">-->
        <!--</div>-->
        <!--</div>-->
        <div class="layui-form-item">
            <label class="layui-form-label">公司名称</label>
            <div class="layui-input-inline">
                <input type="text" name="title" placeholder="模糊查询"
                       autocomplete="off" class="layui-input" id="company">
            </div>
            <label class="layui-form-label">手机号码</label>
            <div class="layui-input-inline">
                <input type="text" name="title" placeholder="请输入"
                       autocomplete="off" class="layui-input" id="phoneNum">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">申请状态</label>
            <div class="layui-input-inline">
                <select name="title" lay-verify="required" id="zhuangTai">
                    <option value=""></option>
                    <option value="0">审核中</option>
                    <option value="1">已通过</option>
                    <option value="2">未通过</option>
                </select>
            </div>
            <button class="layui-btn layui-btn-primary" onclick="tijiao()" type="button" id="btn">搜索</button>
        </div>

    </form>
</div>
<div>
    <div class="nav">用户投放列表
        <table id="demo" lay-filter="test"></table>
    </div>

</div>
<div>
    <div class="yanse">版权所有 Copyright2017 All Rights Reserved</div>
    <div class="yanse">上海定希自有设备租赁有限公司 <a href="http://www.miitbeian.gov.cn">沪ICP备17052837号-1</a></div>
</div>
<script>
    layui.use('table', function () {
        var table = layui.table;

        //第一个实例
        table.render({
            elem: '#demo'
            , height: 475
            , width: 1325
            , url: '/api/getCompanyList' //数据接口
            , page: true //开启分页
            , cols: [[ //表头
                {field: 'companyName', title: '公司名称', width: 200, sort: true, fixed: 'left'}
                , {field: 'phone', title: '手机号码', width: 200, sort: true}
                , {field: 'depositAddress', title: '设备存放地点', width: 300, sort: true}
                , {field: 'status', title: '状态', width: 100, templet: '#titleTpl2'}
                , {field: 'updusername', title: '最后操作人', width: 150, sort: true}
                , {
                    field: 'updtime', title: '操作时间', width: 200, templet: function (d) {
                        var times = RiQi(d.addtime.time / 1000);
                        return times;
                    }
                }
                , {field: 'title', title: '操作', toolbar: '#titleTpl'}
            ]]
        });
        table.on('tool(test)', function (obj) { //注：tool是工具条事件名，test是table原始容器的属性 lay-filter="对应的值"
            var data = obj.data; //获得当前行数据
            var layEvent = obj.event; //获得 lay-event 对应的值（也可以是表头的 event 参数对应的值）
            var tr = obj.tr; //获得当前行 tr 的DOM对象

            if (layEvent === 'del') { //查看
                layer.confirm('真的删除行么', function (index) {
                    layer.close(index);
                    $.ajax(
                        {
                            url: '/api/deleteCompany',
                            data: {id: data.id},
                            type: 'get',
                            dataType: 'json',
                            success: function (data) {
                                if (data.role == 2) {
                                    layer.msg(data.msg);
                                } else {
                                    window.location.reload();
                                }
                            },
                            error: function (error) {
                                //请求失败  获取的报错信息
                                console.log(error);
                            }
                        }
                    );

                });

            } else if (layEvent === 'detail') {
                window.location.href = '/putIn/audit.html?_ijt=' + data.id
            }else if(layEvent === 'check'){
                layui.use('layer', function () {
                    var layer = layui.layer;
                    layer.open({
                        type: 2,
                        area: ['400px', '200px'],
                        content: "/putIn/bangding.html?_ijt=" + data.id
                    });
                });
            }

        });
    });

    function RiQi(sj) {
        var now = new Date(sj * 1000);
        var year = now.getFullYear();
        var month = now.getMonth() + 1;
        var date = now.getDate();
        var hour = now.getHours();
        var minute = now.getMinutes();
        var second = now.getSeconds();
        if (month < 10) {
            month = '0' + month;
        }
        if (date < 10) {
            date = '0' + date;
        }
        if (hour < 10) {
            hour = '0' + hour;
        }
        if (minute < 10) {
            minute = '0' + minute;
        }
        if (second < 10) {
            second = '0' + second;
        }
        return year + "-" + month + "-" + date + " " + hour + ":" + minute + ":" + second;
    }

</script>
<script type="text/html" id="titleTpl">
    <a class="layui-btn layui-btn-xs layui-btn-normal" lay-event="detail">审核</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
    {{#  if(d.status == 1){ }}
    <a class="layui-btn layui-btn-xs" lay-event="check">绑定</a>
    {{#  } }}
</script>

<script type="text/html" id="titleTpl2">
    {{# if(d.status=='0'){ }}
    审核中
    {{# } else if(d.status=='1'){ }}
    已通过
    {{# } else if(d.status=='2'){ }}
    未通过
    {{# } }}
</script>
<script>
    layui.use('form', function () {
        var form = layui.form;
    });

    function tijiao() {
        var phone = $('#phoneNum').val();
        var zt = $('#zhuangTai').val();
        var com = $('#company').val();
        if((phone==null || phone == "")&&(zt==null || zt == "")&&(com==null || com == "") ){
            layer.msg("输入向不能全为空！");
        }else {
            layui.use('table', function () {
                var table = layui.table;

                //第一个实例
                table.render({
                    elem: '#demo'
                    , height: 475
                    , width: 1325
                    , url: '/api/getCompanyBySearchList' //数据接口
                    , where: {phone: phone, status: zt, companyName: com}
                    , page: true //开启分页
                    , cols: [[ //表头
                        {field: 'companyName', title: '公司名称', width: 200, sort: true, fixed: 'left'}
                        , {field: 'phone', title: '手机号码', width: 200, sort: true}
                        , {field: 'depositAddress', title: '设备存放地点', width: 300, sort: true}
                        , {field: 'status', title: '状态', width: 100, templet: '#titleTpl2'}
                        , {field: 'updusername', title: '最后操作人', width: 150, sort: true}
                        , {
                            field: 'updtime', title: '操作时间', width: 200, templet: function (d) {
                                var times = RiQi(d.addtime.time / 1000);
                                return times;
                            }
                        }
                        , {field: 'title', title: '操作', toolbar: '#titleTpl'}
                    ]]
                });
            });
        }
    }

</script>


</body>
</html>